<!DOCTYPE html>
<html lang="en">
<head>
    <title>修改密码</title>
    <%include("/WEB-INF/views/common/basejs.html"){}%>
    <script>
        //全局定义一次, 加载formSelects
        var formSelects;
        layui.use(['form','layer','jquery'],function(){
            var form = layui.form
                ,layer = layui.layer,
                $=layui.jquery;
            //提交form监听表单
            form.on('submit(save)',function(data){
                //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                var password=data.field.password;
                var confirmPassword=data.field.confirmPassword;
                if(!(password===confirmPassword)){
                    layer.msg("前后密码输入不一致",{icon:2});
                    return false;
                }
                $.ajax({
                    url:basePath+'/user/updatePassword',
                    type:'post',
                    data:data.field,
                    dataType:'json',
                    success:function(data){
                        window.parent.closeUpdatePasswordPage();
                        if(data.code==0){
                            //添加成功之后关闭当前窗口
                            window.parent.layer.msg(data.msg,{icon:1});
                        }else{
                            window.parent.layer.msg(data.msg,{icon:2});
                        }
                    },
                    error:function(e){
                        window.parent.closeUpdatePasswordPage();
                    }
                });

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });
    </script>
</head>
<body>
<form class="layui-form layui-form-pane" action="" style="padding-top:10px;padding-left:20px;">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input name="password" type="password" lay-verify="required"  autocomplete="off" placeholder="请输入新密码" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input name="confirmPassword" type="password" lay-verify="required"  autocomplete="off" placeholder="请输入确认密码" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <button id="form-submit" class="layui-btn" lay-submit lay-filter="save"></button>
    </div>
</form>
</body>
</html>